<?php
namespace App\Services;
use App\Models\TeachingAidModel;

class TeachingAidService{

	/**
	 * 获取教具列表
	 * @param int $tid
	 * @return object $aidList
	 */
	public function getAidList($tid){
		$aidList = TeachingAidModel::orderBy('id','desc')
				->where('isshow',1)
				->where('at_id',$tid)
				->select('id','at_id','picture','name','price','item_num','stock','status','sale_num','add_date','unit')
				->get();
		return $aidList;
	}

	/**
	 * 获取教具信息
	 * @param string $name
	 * @return object $aidInfo
	 */
	public function getAidInfoByName($name){
		$aidInfo = TeachingAidModel::where('name',$name)->first();
		return $aidInfo;
	}

	/**
	 * 获取教具信息
	 * @param int $id
	 * @return object $aidInfo
	 */
	public function getAidInfoById($id){
		$aidInfo = TeachingAidModel::where('id',$id)->first();
		return $aidInfo;
	}

	/**
	 * 添加教具
	 * @param array $data
	 * @return bool $res
	 */
	public function insertAid($data){
		$res = TeachingAidModel::insert($data);
		return $res;
	}

	/**
	 * 更新教具
	 * @param array $data
	 * @param int $id
	 * @return bool $res
	 */
	public function modifyAid($id,$data){
		$res = TeachingAidModel::where('id',$id)->update($data);
		return $res;
	}

}